      #include <ros/ros.h>                 //温度和定位返回
      #include <serial/serial.h>  //ROS已经内置了的串口包 
      #include <std_msgs/String.h> 
      #include <std_msgs/Empty.h> 
      #include <geometry_msgs/Twist.h>
      serial::Serial ser; //声明串口对象
      ros::Publisher read_pub; 
      std_msgs::String result;
      void write_callback(const std_msgs::String::ConstPtr& msg) 
      { 
	      //ROS_INFO_STREAM("Writing to serial port" <<msg->data); 
              //std_msgs::String result;
	      if(msg->data=="t")
	      {
	       //read_pub.publish(result);
                ser.write(msg->data);
                if(ser.available()){ 
			      result.data = ser.read(ser.available()); 
                              read_pub.publish(result);
		      } 
		      ser.flush ();//清空串口存储空间
                
	      }  
              if(msg->data=="G")
	      {
                ser.write(msg->data);
	       //read_pub.publish(result);
                if(ser.available()){ 
			      result.data = ser.read(ser.available()); 
                              read_pub.publish(result);
		      } 
		      ser.flush ();//清空串口存储空间
	      }  
              
      } 
      int main (int argc, char** argv) 
      { 
	      //初始化节点 
	      ros::init(argc, argv, "Tempurature_node"); 
	      //声明节点句柄 
	      ros::NodeHandle nh; 
	      //订阅主题，并配置回调函数 
	      ros::Subscriber write_sub = nh.subscribe("/read", 1000, write_callback); 
	      //发布主题 
	      read_pub = nh.advertise<std_msgs::String>("/write", 1000);
         
	      try 
	      { 
		      //设置串口属性，并打开串口 
		      ser.setPort("/dev/ttyUSB1"); 
		      ser.setBaudrate(115200); 
		      serial::Timeout to = serial::Timeout::simpleTimeout(1000); 
		      ser.setTimeout(to); 
		      ser.open(); 
	      } 
	      catch (serial::IOException& e) 
	      { 
	      	      ROS_ERROR_STREAM("Unable to open port "); 
	      return -1; 
	      } 
	      //检测串口是否已经打开，并给出提示信息 
	      if(ser.isOpen()) 
	      { 
	      	      ROS_INFO_STREAM("Serial Port initialized"); 
	      } 
	      else 
	      { 
	      	      return -1; 
	      } 
	      //指定循环的频率 
	      ros::Rate loop_rate(50); 
	      //std_msgs::String result;
	      while(ros::ok()) 
	      { 
		      //处理ROS的信息，比如订阅消息,并调用回调函数 
		      ros::spinOnce(); 
		      loop_rate.sleep(); 
	      } 
        
      } 
